part of '../repository.dart';

const _kLearningEventMarkedAsUnknownValue = 'marked_as_unknown';
const _kLearningEventMarkedAsRememberedValue = 'marked_as_remembered';
const _kLearningEventMarkedAsUnrememberedValue = 'marked_as_unremembered';
const _kLearningEventMarkedAsBadlyRememberedValue = 'marked_as_badly_remembered';
const _kLearningEventMarkedAsCompletelyLearnedValue = 'marked_as_completely_learned';
const _kLearningEventAddedToLearningQueueValue = 'added_to_learning_queue';

class _LearningEventDto extends Equatable {
  const _LearningEventDto._internal({
    required this.learningEventString,
  });

  final String learningEventString;

  @override
  List<Object?> get props {
    return [
      learningEventString,
    ];
  }

  factory _LearningEventDto.fromString(String learningEventString) {
    return _LearningEventDto._internal(
      learningEventString: learningEventString,
    );
  }

  factory _LearningEventDto.fromEntity(LearningEvent learningEvent) {
    final learningEventString = switch (learningEvent) {
      LearningEvent.markedAsUnknown => _kLearningEventMarkedAsUnknownValue,
      LearningEvent.markedAsRemembered => _kLearningEventMarkedAsRememberedValue,
      LearningEvent.markedAsUnremembered => _kLearningEventMarkedAsUnrememberedValue,
      LearningEvent.markedAsBadlyRemembered => _kLearningEventMarkedAsBadlyRememberedValue,
      LearningEvent.markedAsCompletelyLearned => _kLearningEventMarkedAsCompletelyLearnedValue,
      LearningEvent.addedToLearningQueue => _kLearningEventAddedToLearningQueueValue,
    };

    return _LearningEventDto._internal(
      learningEventString: learningEventString,
    );
  }

  @override
  String toString() {
    return learningEventString;
  }

  LearningEvent toEntity() {
    return switch (learningEventString) {
      _kLearningEventMarkedAsUnknownValue => LearningEvent.markedAsUnknown,
      _kLearningEventMarkedAsRememberedValue => LearningEvent.markedAsRemembered,
      _kLearningEventMarkedAsUnrememberedValue => LearningEvent.markedAsUnremembered,
      _kLearningEventMarkedAsBadlyRememberedValue => LearningEvent.markedAsBadlyRemembered,
      _kLearningEventMarkedAsCompletelyLearnedValue => LearningEvent.markedAsCompletelyLearned,
      _kLearningEventAddedToLearningQueueValue => LearningEvent.addedToLearningQueue,
      _ => throw UnimplementedError(),
    };
  }
}
